
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="purchase/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="purchase/css/commonly-used-show.css" />
    <script type="text/javascript" src="purchase/js/jquery.min.js"></script>
    <script type="text/javascript" src="purchase/js/bootstrap.js" ></script>
    <script type="text/javascript" src="purchase/js/overall.js"></script>
    <script type="text/javascript" src="purchase/js/jquery.cookie.js"></script>

     <title>修改密码</title>


</head>

<body class="mybody">


<c:if test="${user_leve == 1}">
    <jsp:include page="theTopMenuAdmin.jsp" />
</c:if>

<c:if test="${user_leve == 2}">
    <jsp:include page="theTopMenuUser.jsp" />
</c:if>


 <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="alert alert-success">


                                <div class="container">
    <div>
        <h3 style="text-align: center">修改用户密码</h3>
        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3"/>

        <div id="personal_user" style="margin-left: 30%; margin-right: 20%">

            <div class="form-group">
                <div >
                    <label style="display: inline-block"><b style="color: red">*&nbsp</b>&emsp;原密码：</label>
                <input style="display: inline-block" type="password" id="user_loing_passwd" class="form-control edit" placeholder="请输入原登录密码" maxlength="16">
                <a href="#" data-toggle="dropdown" data-hover="dropdown"><img id="show_hide1" onclick="hideShowPsw1()" src="purchase/img/hide_paswd.png" width="20px" height="20px"/></a>
                 <span id="upawd1" style="font-size:10px; color: red;"></span>
                </div>

            </div>

            <div class="form-group">
                <div >
                    <label style="display: inline-block"><b style="color: red">*&nbsp</b>&emsp;新密码：</label>
                <input style="display: inline-block" type="password" id="new_user_loing_passwd" class="form-control edit" placeholder="请输入新密码" maxlength="16">
                <a href="#" data-toggle="dropdown" data-hover="dropdown"><img id="show_hide" onclick="hideShowPsw()" src="purchase/img/hide_paswd.png" width="20px" height="20px"/></a>
                 <span id="upawd" style="font-size:10px; color: red;"></span>
                 </div>

            </div>

            <div class="form-group">
                 <div>
                     <label style="display: inline-block"><b style="color: red">*&nbsp</b>确认密码：</label>
                <input style="display: inline-block" type="password" id="ok_user_loing_passwd" class="form-control edit" placeholder="请输入确认密码" maxlength="16">
                <a href="#" data-toggle="dropdown" data-hover="dropdown"><img id="show_hidely" onclick="hideShowPswly()" src="purchase/img/hide_paswd.png" width="20px" height="20px"/></a>
                 <span id="upawdly" style="font-size:10px; color: red;"></span>
                 </div>

            </div>

            <div class="form-group" >
                            <div >
                                 <label style="display: inline-block"><b style="color: red">*&nbsp</b>电子邮箱：</label>
                                 <input style="display: inline-block" type="email" class="form-control edit" id="user_email" placeholder="请输入电子邮箱" maxlength="20">
                            <span id="email" style="font-size:10px; color: red;"></span>
                            </div>
                        </div>

        </div>


        <div class="text-center" style="margin-top: 50px;">
            <div class="form-group">
                <input type="button" value="修改" class="btn btn-primary" onclick="updtaPasswd()">
                <input type="reset" value="重置" class="btn btn-danger interval" onclick="reset()">
            </div>

            <div class="text-center">
                        <span id="user_messge" style="font-size:10px; color: red;"></span>
                    </div>

        </div>

    </div>
</div>


                            </div>
                        </div>
                    </div>
                </div>
        </div>





<script type="text/javascript">

    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    //重置输入框
    function reset(){
        var addUser = document.getElementById("personal_user");
        var ipts = addUser.getElementsByTagName("input");
        for (var i = 0; i < ipts.length; i++){
            ipts[i].value = "";
        }
    }


    function updtaPasswd(){
        var userLoingPasswd = $("#user_loing_passwd").val();
        var newuserLoingPasswd = $("#new_user_loing_passwd").val();
        var okuserLoingPasswd = $("#ok_user_loing_passwd").val();
        var userEmail = $("#user_email").val();

        if ($.isEmptyObject(userLoingPasswd)){
            $("#upawd1").text("原密码不能为空");
            return;
        }else {
            $("#upawd1").text("");
        }

        if ($.isEmptyObject(newuserLoingPasswd)){
            $("#upawd").text("新密码不能为空");
            return;
        }else if (!checkpwd(newuserLoingPasswd)){
            $("#upawd").text("新密码强度过低");
            return;
        }else {
            $("#upawd").text("");
        }

        if ($.isEmptyObject(okuserLoingPasswd)){
            $("#upawdly").text("确认密码不能为空");
            return;
        }else if(newuserLoingPasswd !== okuserLoingPasswd){
            $("#upawdly").text("两次密码不一致");
            return;
        }else {
            $("#upawdly").text("");
        }


        if($.isEmptyObject(userEmail)){
            $("#email").text("电子邮箱为空");
            return;
        }else if (!checkEmail(userEmail)){
            $("#email").text("邮箱格式不正确");
            return;
        }else {
            $("#email").text("");
        }


        var postUrl = "${pageContext.request.contextPath}/member/userInformation";
        var str = {
            "id": userdt.result.id,
            "userLoginPwd": okuserLoingPasswd,
            "userEmail": userEmail
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status === 0){
                    $("#user_messge").text(data.msg);
                }else {
                    $.removeCookie('pawd', { path: '/' });
                    location.href = "${pageContext.request.contextPath}/login";
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function hideShowPsw1(){
        var type = $("#user_loing_passwd").attr("type");
        if (type === "password"){
            $("#user_loing_passwd").attr("type","text");
            $("#show_hide1").attr("src","purchase/img/show_paswd.png");
        }else {
            $("#user_loing_passwd").attr("type","password");
            $("#show_hide1").attr("src","purchase/img/hide_paswd.png");
        }
    }

    function hideShowPsw(){
        var type = $("#new_user_loing_passwd").attr("type");
        if (type === "password"){
            $("#new_user_loing_passwd").attr("type","text");
            $("#show_hide").attr("src","purchase/img/show_paswd.png");
        }else {
            $("#new_user_loing_passwd").attr("type","password");
            $("#show_hide").attr("src","purchase/img/hide_paswd.png");
        }
    }

    function hideShowPswly(){
        var type = $("#ok_user_loing_passwd").attr("type");
        if (type === "password"){
            $("#ok_user_loing_passwd").attr("type","text");
            $("#show_hidely").attr("src","purchase/img/show_paswd.png");
        }else {
            $("#ok_user_loing_passwd").attr("type","password");
            $("#show_hidely").attr("src","purchase/img/hide_paswd.png");
        }
    }

</script>

</body>
</html>
</span>